﻿<%@ WebHandler Language="C#" Class="ProductType_Add" %>

using System;
using System.Web;
using System.Text;
using Newtonsoft.Json;

//System.Web.SessionState.IReadOnlySessionState 增加这个接口类，SESSION可以直接访问
public class ProductType_Add : IHttpHandler, System.Web.SessionState.IReadOnlySessionState 
{

    OTS.BLL.ProductTypeBLL dll = new OTS.BLL.ProductTypeBLL();
    public void ProcessRequest(HttpContext context)
    {
        //检验是否登录
        OTS.Common.PageSuccess page = new OTS.Common.PageSuccess();
        if (!OTS.BaseLogin.validataModule(context, (int)OTS.enumSysRight.ProductTypeManager))
        {
            page.success = false;
            page.msg = "非法操作！";

        }
        else
        {
            string _parentId = context.Request["parent_id"];
            string _typeName = context.Request["type.type_name"];
            string _des = context.Request["type.description"];



            if (null != _parentId && !"".Equals(_parentId) && null != _typeName && !"".Equals(_typeName))
            {
                if ("root".Equals(_parentId)) _parentId = "1";
                OTS.Model.product_type node = new OTS.Model.product_type();
                node.des = _des;
                node.typeName = _typeName;
                node.parentId = int.Parse(_parentId);
                node.state = 0; //用户添加 
                dll.Add(node);

                page.success = true;
                page.msg = "添加成功！";
            }
            else
            {
                page.success = false;
                page.msg = "参数有误！";

            }
        }
        
        context.Response.ContentType = "application/x-json";
        context.Response.Charset = "utf-8";
        context.Response.Write(JavaScriptConvert.SerializeObject(page));
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}